package com.zcurd.model;

import java.util.List;
import java.util.Map;

import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Model;
import com.zcurd.common.tool.DbMetaTool;

public class SysJob extends Model<SysJob> {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	public static final SysJob me =new SysJob();
	
	public Map<String, Object> getJobType() {
		
		return DbMetaTool.getDictData("select '1' 'key', 'cron作业' 'text' union all select '2', '一次任务' ");
	}


	public List<SysJob> getJobList() {
		
		return find("select * from sys_job");
	}


	public Map<String, Object> getRunStatus() {
		
		return DbMetaTool.getDictData("select distinct dict_key as 'key', dict_value as 'text' from sys_dict where dict_type='job_status'");
	}


	public int useAndforb(Integer id) {
		int enable=me.findById(id).get("enable");
		int num=0;
		if(enable==0){
		num= Db.update("update sys_job set enable=1 where id ="+id);
		}
		if(enable==1){
		num= Db.update("update sys_job set enable=0 where id ="+id);
		}
		return num;
	}	

}
